package mp3seller.daos;

import java.util.HashMap;

import mp3seller.entities.Admin;
import mp3seller.util.Util;
/**
 * Classe de persistencia padrao DAO para Administradores do sistema
 * @author Raoni
 *
 */
public class AdminDAO {
	
	private HashMap<Long, Admin> admins = new HashMap<Long, Admin>();
	/**
	 * pegar admistristrado dado login e senha
	 * @param login
	 * @param pass
	 * @return admin
	 */
	public Admin getAdmin(String login, String pass){
		Admin admin = getAdmin(login);
		if(admin != null && admin.getPassword().equalsIgnoreCase(pass)){
			return admin;
		}
		
		return null;
	}
	/**
	 * salvar admimistrador
	 * @param admin
	 */
	public void saveAdmin(Admin admin) {
		admin.setId(Util.nextCode(admins.keySet()));
		admins.put(admin.getId(), admin);
	}
	/**
	 * deletar admimistrador
	 * @param id
	 */
	public void deleteAdmin(long id) {		
		admins.remove(getAdmin(id).getId());
	}	
	/**
	 * deletar admimistrador
	 * @param admin
	 */
	public void deleteAdmin(Admin admin) {
		admins.remove(admin.getId());
	}
	/**
	 * atualizar admimistrador
	 * @param admin
	 */
	public void updateAdmin(Admin admin) {
		admins.put(admin.getId(), admin);
	}
	/**
	 * pegar admimistrador
	 * @param id
	 * @return
	 */
	public Admin getAdmin(long id) {
		return admins.get(id);
	}
	/**
	 * pegar admimistradores
	 * @return
	 */
	public HashMap<Long, Admin> getAdmin() {
		return admins;
	}
	/**
	 * pegar admimistrador pelo login
	 * @param login
	 * @return
	 */
	public Admin getAdmin(String login){
		for(Admin admin : admins.values()){
			if(admin.getLogin().equalsIgnoreCase(login)){
				return admin;
			}
		}
		return null;
	}	
}
